<template>
  <div>
    <!-- 头部 -->
    <goodShopingTitle :shoping="shoping"></goodShopingTitle>
    <div class="main">
      <!-- 商品 -->
      <span class="main_goods" @click="main_goodsFn">商品</span>
      <!-- 评价 -->
      <span class="main_appraise" @click="main_appraiseFn">评价</span>
    </div>
    <!-- 商品展示 -->
    <router-view></router-view>

    <van-dialog v-model="show" :showConfirmButton="false">
      <div class="pig">
        <div class="load_img"></div>
      </div>
    </van-dialog>
  </div>
</template>

<script>
import goodShopingTitle from "../components/goodShopingTitle.vue";
import { goodShoping } from "../api/goodShoping";
import move from "../components/move.vue";
export default {
  data() {
    return {
      shopid:
        this.$route.query.shopid || JSON.parse(localStorage.getItem("shopid")), //商铺ID
      shoping: {}, //商铺信息
      show: false, //动画效果
    };
  },
  components: {
    goodShopingTitle,
    move,
  },
  watch: {
    shopid: {
      immediate: true, // 立即执行
      deep: true, // 深度侦听复杂类型内变化
      handler(newVal, oldVal) {
        localStorage.setItem("shopid", JSON.stringify(this.shopid));
      },
    },
  },
  created() {
    this.show = true;
    goodShoping(this.shopid).then((res) => {
      this.shoping = res.data;
      // 自点一次商品
      this.main_goodsFn();
      this.show = false;
    });
  },
  methods: {
    main_goodsFn() {
      this.$router.push({
        path: "/goodShoping/shopinggoods",
        query: {
          shopid: this.shopid,
          tips:
            this.shoping.piecewise_agent_fee &&
            this.shoping.piecewise_agent_fee.tips,
        },
      });
    },
    main_appraiseFn() {
      this.$router.push({
        path: "/goodShoping/goodsEvaluate",
        query: {
          shopid: this.shopid,
        },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  display: flex;
  background-color: #fff;
  height: 50px;
  .main_goods {
    flex: 1;
    line-height: 50px;
    text-align: center;
  }
  .main_appraise {
    flex: 1;
    line-height: 50px;
    text-align: center;
  }
}

.van-dialog {
  z-index: 2002;
  height: 300px;
  background-color: transparent;
}
.pig {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100px;
  height: 100px;
  .load_img {
    width: 100%;
    height: 100%;
    background: url("..//assets/6.png") no-repeat 0 0;
    transform: translateY(0);
    position: relative;
    animation: move 0.6s infinite;
    z-index: 11;
    left: 0;
  }
}

@keyframes move {
  to {
    transform: translate(0, -100%);
  }
}
</style>